package org.example.ymcc.producer;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.ymcc.constant.MQConstants;
import org.example.ymcc.domain.CourseCollect;
import org.example.ymcc.mapper.CourseCollectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CourserOnlineProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Autowired
    private CourseCollectMapper courseCollectMapper;

    public void sendMessage(List<Long> CourseIds){
        List<CourseCollect> courseCollects = courseCollectMapper.selectList(new LambdaQueryWrapper<CourseCollect>().in(CourseCollect::getCourseId, CourseIds));
        //短信  邮箱   站内信
        rocketMQTemplate.syncSend(MQConstants.COURSE_ON_LINE_TOPIC+":"+MQConstants.COURSE_ON_LINE_TAG,
                MessageBuilder.withPayload(JSON.toJSONString(courseCollects)).build());
    }
}
